﻿
Partial Class Interfaz_frmAdminCreacionCodigoItem
    Inherits System.Web.UI.Page
    Private CL As New ControladorLogica

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If CL.visibilidadesFormsInternos("Administracion", Session("user").ToString) = False Then
            Response.Redirect("Index.aspx")
        End If
        Dim ArrayProveedor As New ArrayList
        Dim ArrayFamilia As New ArrayList
        Dim i As Integer

        ArrayProveedor = CL.ObtenerProveedor()
        ArrayFamilia = CL.ObtenerFamilia()

        If Not Page.IsPostBack Then
            For i = 0 To ArrayProveedor.Count - 1
                Me.DropProv.Items.Add(DirectCast(ArrayProveedor.Item(i), Proveedor).Rznsocial)
            Next
            For i = 0 To ArrayFamilia.Count - 1
                Me.DropFamilia.Items.Add(DirectCast(ArrayFamilia.Item(i), Familia).Nombre)
            Next
        End If
    End Sub

#Region "Funciones"

    Public Sub Mensaje(ByVal msg As String)
        Dim alertScript As String = "<script language=JavaScript runat=server>"
        alertScript &= "alert('" & msg & "');"
        alertScript &= "</script>"
        ClientScript.RegisterClientScriptBlock(Page.GetType(), "clientScrip", alertScript)
    End Sub

    Private Sub IngresarNuevoItem()

        Dim nombre As String = Me.Txtnom.Text
        Dim descripcionFormal As String = Me.TxtDescFormal.Text
        Dim descripcionInformal As String = Me.TxTDescInformal.Text
        Dim stockMinimo As String = Me.TxTStockMinimo.Text
        Dim refFamilia As String = Me.DropFamilia.Text

        Dim query As String = "select id from familiamateriales where nombre='" + refFamilia + "'"
        Dim idFamilia As String = CL.Ejecuta(query).Item("id").ToString

        If descripcionFormal <> "" And descripcionInformal <> "" And stockMinimo <> "" And refFamilia <> "" Then
            Dim nuevoMaterial As New Material()
            nuevoMaterial.Nombre = nombre
            nuevoMaterial.DescripcionFormal = descripcionFormal
            nuevoMaterial.DescripcioninFormal = descripcionInformal
            nuevoMaterial.STOCKMINIMO = stockMinimo
            nuevoMaterial.RefFAmilia = idFamilia
            CL.MaterialTemporal(nuevoMaterial)
            clean()
            Me.Mensaje("El material a sido ingresado con exito")
        Else
            Me.Mensaje("Dato Faltante, rellene todos los campos")
        End If

    End Sub

    Private Sub clean()
        Me.Txtnom.Text = ""
        Me.TxtDescFormal.Text = ""
        Me.TxTDescInformal.Text = ""
        Me.Txtnom.Text = ""
        Me.TxTStockMinimo.Text = ""
    End Sub

#End Region

#Region "Botones"
   

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        IngresarNuevoItem()
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        clean()
    End Sub
#End Region
End Class
